Imports RSToolKit.ReportService

Public Class frmMove

    Private rs As ReportServer
    Private alRS As New ArrayList

    Public WriteOnly Property Nodes() As TreeView
        Set(ByVal value As System.Windows.Forms.TreeView)
            Me.tvReports = value
        End Set
    End Property

    Public ReadOnly Property ReportServer() As ReportServer
        Get
            Return Me.rs
        End Get
    End Property

    Public WriteOnly Property Copy() As Boolean
        Set(ByVal value As Boolean)
            If value Then
                Me.Text = "Copy Object - Select Destination"
                Me.btnOK.Text = "&Copy"
            End If
        End Set
    End Property

    Public ReadOnly Property Item() As CatalogItem
        Get
            If TypeOf (tvReports.SelectedNode.Tag) Is RSToolKit.ReportServer Then
                Return New CatalogItem
            Else
                Return Me.tvReports.SelectedNode.Tag
            End If
        End Get
    End Property

    Public Sub Add(ByVal Node As ReportServer)
        alRS.Add(Node)
        UpdateTV()
    End Sub

    Private Sub UpdateTV()
        Me.tvReports.BeginUpdate()
        Me.tvReports.Nodes.Clear()
        For Each tempRS As ReportServer In alRS
            Me.tvReports.Nodes.Add(tempRS.GetFolderAsNodes)
        Next
        Me.tvReports.EndUpdate()
        'Me.tvReports.ExpandAll()
    End Sub

    Private Sub frmVerschieben_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Function GetMasterNode(ByVal Node As TreeNode) As TreeNode
        Dim myNode As New TreeNode
        If Not Node.Parent Is Nothing Then
            myNode = GetMasterNode(Node.Parent)
        Else
            myNode = Node
        End If
        Return myNode
    End Function

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If Me.tvReports.SelectedNode.Tag.ToString = "RSToolKit.ReportServer" Then
            Me.rs = Me.tvReports.SelectedNode.Tag
        Else
            Me.rs = GetMasterNode(Me.tvReports.SelectedNode).Tag
        End If
        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub
End Class